﻿using System.Collections;
using System.ComponentModel;
using System.ComponentModel.Composition;
using System.Windows.Data;
using Caliburn.Micro;
using Scrabble.Model;

namespace Scrabble.ViewModels
{
    [Export(typeof(PlayerViewModel)), PartCreationPolicy(CreationPolicy.NonShared)]
    public sealed class PlayerViewModel : Screen
    {
        private readonly IPlayer _player;
        private readonly InputBoxViewModel _inputBox;
        private readonly ICollectionView _eventLog;

        public PlayerViewModel(IGame game, IPlayer player)
        {
            _player = player;
            _inputBox = new InputBoxViewModel(game, player);
            _eventLog = new ListCollectionView((IList) game.EventLog)
                        {
                            Filter = logEntry => ((IGameEvent) logEntry).Player == Player
                        };

            DisplayName = Player.Name;
        }

        public IPlayer Player 
        {
            get { return _player; }
        }

        public IInputBox InputBox
        {
            get { return _inputBox; }
        }

        public ICollectionView EventLog
        {
            get { return _eventLog; }
        }
    }
}